<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mainframe
 *
 * @author Alexander.Chajka
 */
class mainframe {
    private $lang_path;

    public function __construct($options) {
        $this->lang_path = 'language/ru.php';
    }
    
    public function translate($string) {
        include_once $this->lang_path;
        $str = str_replace (' ', '_', $string);

        if (defined($str)) return eval('echo '.$str.';');
        else return $string;
    }

    public function create() {
        $link = $this->getCmd('link');
        $alias = $this->getCmd('alias');

        return ($alias ? $alias : $link);
    }

    public function register() {
        global $user;
        
        $email = $this->getCmd('email');
        $pass = $this->getCmd('pass');
        $token = $this->getUserToken();

        $check_state = $user->checkEmail($email);
        if (!$check_state) {
            if (is_numeric($check_state)) {
                $str  = $this->translate('You_already_registered').'! ';
                $str .= $this->translate('Forgot_Password').'?';
            } else {
                $str = $check_state;
            }
            return $str;
        } else
            return $user->register($email, $pass, $token);
    }
    
    public function getUserToken() {
        return $_COOKIE['token'] ? $_COOKIE['token'] : $_SESSION['token'];
    }

    public function getCmd($name, $defult = '') {
        if (isset($_REQUEST[$name])) {
            return ($_REQUEST[$name] ? $_REQUEST[$name] : $defult);
        } else {
            return $defult;
        }

    }
}
?>
